<template>
    <v-container>
        <v-row>
            <v-text-field v-model="bookBo.title" label="单词本名称" required hide-details color="primary"/>
        </v-row>
        <v-row>
            <p> &nbsp;</p>
        </v-row>
        <v-row>
            <v-select color="primary" v-model="bookBo.langId" clearable label="选择语种" item-title="lang" item-value="langId"
                :items="langList" variant="outlined" />
        </v-row>
        <v-row>
            <v-select color="primary" clearable chips label="选择标签" item-title="name" item-value="id" :items="labelList"
                v-model="bookBo.label" multiple variant="outlined" />
        </v-row>
        <v-row>
            <v-radio-group color="primary" label="数据scope" inline v-model="bookBo.status">
                <v-radio label="public" value="PUBLIC"></v-radio>
                <v-radio label="protected" value="PROTECTED"></v-radio>
                <v-radio label="private" value="PRIVATE"></v-radio>
            </v-radio-group>
        </v-row>
        <v-row>
            <v-textarea v-model="bookBo.remark" label="备注" required hide-details color="primary"/>
        </v-row>
    </v-container>
</template>

<script>
import { adminAddBook, adminUpdateBook } from '@/api/adminBook';

export default {
    props: {
        langList: { default: [] },
        labelList: { default: [] },
    },
    data() {
        return {
            bookBo: {}
        }
    },
    methods: {
        setBookBo(bookBo) {
            this.bookBo = bookBo
        },
        save(action, callback) {
            if (this.bookBo == null || this.bookBo.title == null || this.bookBo.title == '') {
                if (callback != null) callback(false)
                return
            }
            if (action == 'save') {
                adminAddBook(this.bookBo).then(resp => {
                    if (resp.code == 1) {
                    }
                    if (callback != null) callback(resp.code == 1)
                })
            } else if (action == 'update') {
                adminUpdateBook(this.bookBo).then(resp => {
                    if (resp.code == 1) {
                    }
                    if (callback != null) callback(resp.code == 1)
                })
            }
        }
    },
}
</script>

<style></style>